# import库
import random as rd
import time
import os
import argparse
import configparser as cp 

irn = 0
#钢铁
oil = 0
# 石油
mny = 0
# 资金
wkr = 0
# 工人
PT = 0
# 生产技术
is_sighed_up = False
# 是否已签到

# 帮助和词典（还有传参）
parser = argparse.ArgumentParser(description='这是一个国家模拟器。我们可以在里面当一个好总统，也可以当暴君。')
parser.add_argument('-n', '--new', default='config.ini', help='开个新存档')
parser.add_argument('-o', '--open', help='打开 .ini的游戏存档')
args = parser.parse_args()

# 创建和读取游戏存档
if args.new:
    os.system('echo [game] > ', args.new, '.ini')
else:
    gf = args.open #gamefile
    config = cp.ConfigParser()
    config.read(gf)
    irn = config['game']['irn']
    oil = config['game']['oil']
    mny = config["game"]['mny']
    wkr = config["game"]['wkr']
    PT = config["game"]['PT']



while True:  # 更改循环条件为True，以便在需要时退出循环
    test = input("请输入命令: ")
    if test == "生产":
        mny += wkr * 2
        print("资金 =", mny,"（+10）\n")
        # 生产模块
    
    elif test == "签到":
        oil += rd.randint(100, 1000)
        mny += rd.randint(1000, 10000)
        wkr += rd.randint(500, 1000)
        PT += 1
        is_sighed_up = True
        print ("签到成功：\n石油 = ", oil, "\n资金 = ", mny, "\n工人 = ", wkr, "\n生产技术 + 1")
        # 签到模块基本动作
    
    elif test == "生产石油":
        if mny >= 1000:  # 确保有足够的资金来生产石油
            mny -= rd.randint(1000, 10000)
            oil += rd.randint(100, 1000)
            print("资金 = ", mny, "（-10）\t石油 = ", oil,"（+5）\n")
        else:
            print("资金不足，无法生产石油\n")
    
    elif test == "我的资料":
        print("石油 = ", oil,"\t资金 = ", mny,"\t工人 = ", wkr,"\t 生产技术 = ", PT, "\n")
    
    # 添加退出循环的命令
    elif test == "退出调试":
        print("我草，你在调试我？！\n")
        # 你在看注释吗
        break

    elif test == '保存':
        config['game']['irn'] = irn
        config['game']['oil'] = oil
        with open(gf, 'w') as configfile:
            config.write(configfile)
    
    else:
        print("这不是命令\n")